from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SKUImage, SKU
from meiduo_admin.serializers.images import ImageSerializer, SKUSerializer
from meiduo_admin.utils import PageNum


class ImagesView(ModelViewSet):
    """
        图片表的增删改查
    """
    # 指定查询集
    queryset = SKUImage.objects.all()
    # 指定序列化器
    serializer_class = ImageSerializer
    # 指定分页器
    pagination_class = PageNum
    # 指定管理员权限
    permission_classes = [IsAdminUser]

    def simple(self, request):
        data = SKU.objects.all()
        ser = SKUSerializer(data, many=True)
        return Response(ser.data)
